<template>
  <div class="app-container">
  
      <el-form ref="form" :model="form" :rules="rules" label-width="180px">
        <el-form-item label="传感器主题名称" prop="sensorsubject">
          <el-input v-model="form.sensorsubject" placeholder="请输入传感器场景主题名称" />
        </el-form-item>
        <el-form-item label="主题说明" prop="description">
          <el-input v-model="form.description" placeholder="请输入场景主题说明" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div> 
  </div>
</template>

<script>
import {  addSensorsubject, updateSensorsubject } from "@/api/snmp/sensorsubject";

export default {
  name: "Sensorsubject",
  data() {
    return {
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sensorsubject: [
          { required: true, message: "传感器主题名称不能为空", trigger: "blur" }
        ],
      }
    };
  }, 
  methods: { 
    // 取消按钮
    cancel() { 
      this.reset();
    }, 
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
        //this.form.id 
          if (this.form.id != null) {
            updateSensorsubject(this.form).then(response => {
              this.$modal.msgSuccess("修改成功"); 
              this.getList();
            });
          } else {
            addSensorsubject(this.form).then(response => {
              this.$modal.msgSuccess("新增成功"); 
              this.getList();
            });
          }
        }
      });
    }
  }
};
</script>
